﻿/// <reference path="TsLinq.d.ts" />
/// <reference path="Linq.ts" />
/// <reference path="DefaultComparer.ts" />
var __extends = this.__extends || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};
var List = (function (_super) {
    __extends(List, _super);
    function List() {
        _super.apply(this, arguments);
    }
    //
    // Adds a new item to the list.
    List.prototype.push = function (item) {
        this._items.push(item);
    };

    //
    //  Clears all items in the dictionary.
    //
    List.prototype.clear = function () {
        this._items = [];
    };

    //
    //  Adds all elements to the current list
    //
    List.prototype.addRange = function (items) {
        var _this = this;
        items.forEach(function (i) {
            return _this.push(i);
        });
    };

    //
    //  Inserts an item on the given position. If no position is given, the item is added as the first item in the collection.
    //
    List.prototype.insert = function (item, position) {
        if (typeof position === "undefined") { position = 0; }
        this._items.splice(position, 0, item);
    };

    //
    //  Removes the first occurrence of a specific object. If the object was not found, an error is thrown.
    //
    List.prototype.remove = function (item, comp) {
        var index = this.indexOf(item, comp);
        if (index == -1) {
            throw new Error('Can\'t find the item to remove.');
        }
        return this.removeAt(index);
    };

    //
    //  Removes the element on the specified position.
    //
    List.prototype.removeAt = function (position) {
        if (position >= this._items.length || position < 0) {
            throw new Error('Position is not in range');
        }
        var result = this._items[position];
        this._items.splice(position, 1);
        return result;
    };
    return List;
})(Linq);
